/*
 * @Author: song
 * @Description:运行时配置 编译器下的帧率 需要和运行的时候保持整数倍的关系
 * @Date: 2024年05月03日 星期五 22:05:17
 * @Modify:
 */

using System;
using SCore.Function.Fixed;
using Function.SerializedPropertyAttribute;
using SCore.Util;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;

namespace Function.SkillEditor.Runtime
{
#if UNITY_EDITOR
    [CustomEditor(typeof(SkillRunMap))]
    public class EditorLineEditor : ObjectDrawEditor<SkillRunMap>
    {
    }
#endif

    [CreateAssetMenu(fileName = "SkillRunMap", menuName = "ScriptableObject/SkillEditor/SkillRunMap",
        order = 3)]
    public class SkillRunMap : SingleScriptableObject<SkillRunMap>
    {
        [Tooltip("编辑器编辑帧率")] private fp _oneFrameTime = 1f / 20f;
        [Head("运行帧率")] [SerializeField] private int _runTargetFrame = 20;

        [NonSerialized] [Head("速度")] private int _speed = 1;


        private fp _runFrameTime = fp.Zero;

        public fp RunFrameRatio
        {
            get
            {
                if (_runFrameTime == fp.Zero)
                {
                    _runFrameTime = 1f / _runTargetFrame;
                }

                return _runFrameTime;
            }
        }

#if UNITY_EDITOR
        /// <summary>
        /// 得到当前编辑器下的逻辑帧
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public int GetECurFame(fp time)
        {
            return (time / _oneFrameTime).AsInt();
        }

        /// <summary>
        /// 得到当前编辑器下的一帧时间
        /// </summary>
        /// <returns></returns>
        public fp GetEOneFrameTime()
        {
            return _oneFrameTime;
        }

#endif

        public void GetCurFrame()
        {
        }

        public int GetSpeed()
        {
            return _speed;
        }
    }
}